package main

import (
	"fmt"
	"sync"
)

type safeMap struct {
	m    map[string]string
	lock sync.Mutex
}

func (s *safeMap) Store(key string, newVal string) (val string, result bool) {
	s.lock.Lock()
	defer s.lock.Unlock()

	val, ok := s.m[key]
	if ok {
		return val, true
	}
	s.m[key] = newVal

	return newVal, true
}

func main() {
	var m = safeMap{
		m: map[string]string{"name": "guoZhang"},
	}

	m.Store("gender", "man")

	fmt.Println(m)
}
